<!-- 继承blog/base.html 文件 --> 
{% extends "blog/base.html" %} 
<!-- 加载自定义标签 --> 
{% load blog_tags %} 
<!-- 使用此处标题块内容替换blog/base.html文件中标题块 --> 
{% block title %}{{ post.title }}{% endblock %} 
<!-- 使用此处内容块代码替换blog/base.html文件中内容块 定制每个页面的特定内容--> 
{% block content %} 
    <h1>{{ post.title }}</h1> 
    <p class="date"> 
        Published {{ post.publish }} by {{ post.author }} 
    </p> 
    {{ post.body|markdown }}  
    <p> 
        <a href="{% url "blog:post_share" post.id %}"> 
            Share this post 
        </a> 
    </p>
{% with comments.count as total_comments %} 
<h2> 
<!-- pluralize 过滤器叫做复数过滤器，当前面的数量是大于1的则自动为comment添加
s，适用于英文--> 
    {{ total_comments }} comment{{ total_comments|pluralize }} 
</h2> 
<!-- 标题 -->
<h2>Similar posts</h2>
<!-- 对于每篇相似文章，显示其标题并变为链接支持跳转 --> 
{% for post in similar_posts %}  
    <p> 
    <a href="{{ post.get_absolute_url }}">{{ post.title }}</a> 
    </p>
<!-- 若没有相似文章显示如下内容 --> 
{% empty %} 
   There are no similar posts yet. 
{% endfor %} 
{% endwith %} 
<!-- 遍历所有评论信息并显示--> 
{% for comment in comments %} 
<div class="comment"> 
    <p class="info"> 
<!--  forloop.counter 标签自动生成循环元素的序号 --> 
    Comment {{ forloop.counter }} by {{ comment.name }} 
    {{ comment.created }}
    </p>
    {{ comment.body|linebreaks }}
</div>
{% empty %}
    <p>There are no comments yet.</p>
{% endfor %} 
{% if new_comment %} 
<h2>Your comment has been added.</h2> 
{% else %}    
    <!-- 添加评论标题--> 
    <h2>Add a new comment</h2> 
    <!-- 评论表单 --> 
    <form method="post"> 
        <!-- 根据后端评论表单自动生成前端评论表单 --> 
    {{ comment_form.as_p }} 
    <!-- 防止远程跨域劫持攻击 --> 
    {% csrf_token %} 
    <!-- 提交评论按钮 --> 
    <p><input type="submit" value="Add comment"></p> 
    </form>
{% endif %} 
{% endblock %}  